/**
 * @file index.js
 * @author swan
 */
const app = getApp()

Page({
    data: {
        indicatorDots: true,
        autoplay: true,
        interval: 5000,
        duration: 1300,
        Height: "",
        IndexBannerUrl: [
            {
                link: '',
                url: '../../images/banner-1.jpg'
            }, {
                link: '',
                url: '../../images/banner-2.jpg'
            }, {
                link: '',
                url: '../../images/banner-3.jpg'
            },
            {
                link: '',
                url: '../../images/banner-4.jpg'
            },
            {
                link: '',
                url: '../../images/banner-5.jpg'
            }

        ]
    },
    imgHeight: function (e) {
        var winWid = swan.getSystemInfoSync().windowWidth; //获取当前屏幕的宽度
        var imgh = e.detail.height; //图片高度
        var imgw = e.detail.width; //图片宽度
        var swiperH = winWid * imgh / imgw + "px"
        this.setData({
            Height: swiperH //设置高度
        })
    },
    bindViewTap: function (event) {
        var cid = event.currentTarget.dataset.cid;
        console.log(cid)
        if (cid == 5) {
            swan.switchTab({
                url: event.currentTarget.dataset.link // 页面跳转地址
            })
        } else {
            if (event.currentTarget.dataset.link) {
                swan.navigateTo({
                    url: event.currentTarget.dataset.link // 页面跳转地址
                })
            }
        }

    },
    onLoad(e) {
        // 监听页面加载的生命周期函数
        let id = e.id;
        if (!id) {
            let pros;
            for (let i = 0; i < getApp().globalData.config.length; i++) {
                if (getApp().globalData.config[i].key == 'pros') {
                    pros = getApp().globalData.config[i];
                    break;
                }
            }
            getApp().rq('/Index/getList', {
                typeid: pros.alis,
                limit: 999,
                sort: pros.sortname,
            }).then(res => {
                this.setData({
                    data: res.data,
                    imgurl: getApp().globalData.imageurl
                })
            })
        } else {
            getApp().rq('/Index/getList', {
                typeid: id,
                limit: 999,
            }).then(res => {
                this.setData({
                    data: res.data,
                    imgurl: getApp().globalData.imageurl,
                });
                console.log(res.data);
            });
        }
    },

    productDetail: function (e) {
        swan.setStorageSync('prodetail', e.currentTarget.dataset.item);
        swan.navigateTo({
            url: '../productDetail/productDetail'
        });
    }

})
